<?php

class Office_modul  extends CI_Model {
	public $select;
	public $dollars;
 
	public function __construct() {
		// Call the Model constructor
		parent::__construct();

		$this -> fproperty();
		$this-> dollars=30;
	}


	/**
	 * Поиск наглавной главная
	 *
	 * @return void
	 * @author
	 */

	public function request($get = false, $start = 0, $finish = 30) {

		$data = false;
		$select_data = array();
		$DB2 = $this -> load -> database('adsent', TRUE, TRUE);

		$select = "SELECT   
 
      
    r.id,  
    r.area, 
    r.building,
    r.contract,
    r.share_area,
    r.object_type ,
    r.adress_name,
    r.region_names,
    r.region_id,
    r.city_name,
    r.city_id,
    r.street_name,
    r.street_id,
    r.home_id, 
    r.price,
    r.currency,   
    r.floor,   
    r.floorn, 
    r.enter,
    
    
    
    r.newtime,
    
    
     
    r.comment_client,
    r.comment_site,
    r.keepday,
    r.for_all,
    r.contact_telefon1,
    r.contact_name1,
    r.contact_telefon2,
    r.contact_name2,
    r.id_phone,
    
    r.phone,
    r.add_phones,
    
    
    
    r.act,
    r.datetime,
    r.moderator, 
    r.name_metro,
    r.id_metro
    
     
   FROM `roffice` `r`  
   $get
   
   GROUP BY r.id
   
   
   LIMIT $start,$finish;";

		$q = $DB2 -> query($select);
		$data = $this -> req($q);
		return $data;
	}

	public function fproperty() {
		$lt = false;

		$DB2 = $this -> load -> database('adsent', TRUE, TRUE);
		$query = $DB2 -> query("SELECT * FROM `property`");

		if ($query -> num_rows() > 0) {
			foreach ($query->result() as $row) {
				$lt[$row -> text] = $row -> val;
			}
		}
		$this -> property = $lt;
		return;
	}

	/**
	 *
	 * @param $array - массив с данными для разбора
	 *
	 * */
	public function req($datas) {
		$data = array();

		$this -> load -> helper('text');
		$this -> load -> helper('see');
		if ($datas -> num_rows() > 0) {

			foreach ($datas -> result() as $row) {

				$data[] = array('id' => $row -> id, 
				'root' => rent_office_object_type($row -> object_type), 
				'building' => rent_office_building($row -> building),
				 'contract' => rent_office_contract($row -> contract), 
				 'enter' => $row -> enter, 
				 'currency' => $row -> currency,
				 'area' => $row -> area, 
				 'past_area' => $row -> share_area, 'r_adress_name' => $row -> adress_name, 
				 'r_region_names' => $row -> region_names, 'r_region_id' => $row -> region_id, 
				 'r_city_name' => $row -> city_name, 'r_city_id' => $row -> city_id, 
				 'r_street_name' => $row -> street_name, 'r_street_id' => $row -> street_id, 
				 'r_home_id' => $row -> home_id,
				 
				    'price_dollar' => rent_flat_current($row -> price, $row -> currency,'dollars',$this->dollars),
				   'price_rubley' => rent_flat_current($row -> price, $row -> currency, 'rubley',$this->dollars),
				
				   
				   
				    'floor' => $row -> floor, 'floorn' => $row -> floorn, 
				   'phone' => $row -> phone, 'aphone' => $row -> add_phones, 
				   'newtime' => $row -> newtime, 'comment_client' => $row -> comment_client,
				    'r_comment_site' => $row -> comment_site, 'r_keepday' => $row -> keepday, 
				    'for_day' => rent_office_for_days($row -> for_all), 
				    'contact_telefon1' => $row -> contact_telefon1, 
				    'contact_name1' => $row -> contact_name1, 
				    'contact_telefon2' => $row -> contact_telefon2, 'contact_name2' => $row -> contact_name2, 'id_phone' => $row -> id_phone, 'r_act' => $row -> act, 'datetime' => $row -> datetime, 'r_moderator' => $row -> moderator, 'metro' => $row -> name_metro, 'metro_id' => $row -> id_metro, 'adsent' => 'roffice', );
			}
		}
		return $data;
	}

}
